const formatTime = date => {
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()
    const hour = date.getHours()
    const minute = date.getMinutes()
    const second = date.getSeconds()

    return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatSeconds = time => {
    let tempTime = Number(time),
        minuteTime = tempTime > 60 ? parseInt(tempTime / 60) : 0,
        secondTime = parseInt(tempTime % 60),
        minute = minuteTime > 10 ? minuteTime : ('0' + minuteTime.toString()),
        second = secondTime > 10 ? secondTime : ('0' + secondTime.toString()),
        result = minute + ':' + second

    return result
}


// 日期格式补0
const formatNumber = n => {
    n = n.toString()
    return n[1] ? n : '0' + n
}


// 检测当前机型的长宽
const nowPhoneWH = () => {
    let a = []
    let res = wx.getSystemInfoSync()
    a[0] = res.windowWidth
    a[1] = res.windowHeight
    return a
}

module.exports = {
    formatTime: formatTime,
    nowPhoneWH,
    formatNumber,
    formatSeconds
}
